package com.farm.forms.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.farm.forms.domain.Rules;
import com.farm.forms.dao.RulesDaoInter;
import com.farm.forms.service.RulesServiceInter;
import com.farm.core.auth.domain.LoginUser;
import com.farm.core.sql.query.DBRule;
import com.farm.core.sql.query.DataQuery;
/* *
 *功能：查询条件服务层实现类
 *详细：
 *
 *版本：v1.1
 *作者：王东
 *日期：20141124
 *说明：
 */
public class RulesServiceImpl implements RulesServiceInter {
	private RulesDaoInter rulesDao;

	@Override
	public Rules insertRulesEntity(Rules entity, LoginUser user) {
		return rulesDao.insertEntity(entity);
	}

	@Override
	public Rules editRulesEntity(Rules entity, LoginUser user) {
		Rules entity2 = rulesDao.getEntity(entity.getId());
		entity2.setTypepara(entity.getTypepara());
		entity2.setSort(entity.getSort());
		entity2.setType(entity.getType());
		entity2.setSign(entity.getSign());
		entity2.setCode(entity.getCode());
		entity2.setTitle(entity.getTitle());
		entity2.setSqlrule(entity.getSqlrule());
		rulesDao.editEntity(entity2);
		return entity2;
	}

	@Override
	public void deleteRulesEntity(String id, LoginUser user) {
		// TODO 自动生成代码,修改后请去除本注释
		rulesDao.deleteEntity(rulesDao.getEntity(id));
	}

	@Override
	public Rules getRulesEntity(String id) {
		// TODO 自动生成代码,修改后请去除本注释
		if (id == null) {
			return null;
		}
		return rulesDao.getEntity(id);
	}

	@Override
	public DataQuery createRulesSimpleQuery(DataQuery query) {
		// TODO 自动生成代码,修改后请去除本注释
		DataQuery dbQuery = DataQuery.init(query, "FARM_FORMS_RULES",
				"ID,TYPEPARA,QUERYID,SORT,TYPE,SIGN,CODE,TITLE,SQLRULE");
		return dbQuery;
	}

	// ----------------------------------------------------------------------------------
	public RulesDaoInter getRulesDao() {
		return rulesDao;
	}

	public void setRulesDao(RulesDaoInter dao) {
		this.rulesDao = dao;
	}

	@Override
	public List<Rules> getRulesByQueryId(String queryId) {
		return rulesDao.selectEntitys(DBRule.addRule(new ArrayList<DBRule>(),
				"QUERYID", queryId, "="));
	}

}
